{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf390
{\fonttbl\f0\fnil\fcharset77 Monaco;}
{\colortbl;\red255\green255\blue255;\red191\green0\blue0;\red0\green0\blue191;\red96\green96\blue96;
}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\fs22 \cf2 // triggersAndPitchFollowers.rtf\cf0 \
\cf2 // Macintosh Compiled versions of these are in the folder called synthdefs\cf0 \
\cf2 // A bunch of Synthdefs from the supercollider docs, some modified, some my own...\cf0 \
\cf2 // Some of the below copyright (C) 2003 - 2006 Jonathan Saggau\cf0 \
\cf2 // License: GPL\cf0 \
\cf2 // Others from SC Docs\cf0 \
\cf2 // License: GPL\cf0 \
\cf2 // Still others from SC-users list\cf0 \
\cf2 // License: free\cf0 \
\
\cf2 //___________________________________________________________________________________________\cf0 \
\cf2 // Amplitude Triggers and pitch - followers\cf0 \
\cf2 //___________________________________________________________________________________________\cf0 \
\
(\
\cf2 // trigger one shot on each pulse (PlayBuf help file)\cf0 \
\cf3 SynthDef\cf0 (\cf4 "JASTempoTrigger"\cf0 , \{ \cf3 arg\cf0  out=0,bufnum=0,impulsesPerSec=2.0, amp=1, triggerID;\
	\cf3 var\cf0  trig;\
	trig = \cf3 Impulse\cf0 .kr(impulsesPerSec);\
	\cf3 SendTrig.kr\cf0 (trig, triggerID, amp); \cf2 //send a trigger to the client\cf0 \
	\cf3 Out\cf0 .ar(out,\
		\cf3 PlayBuf\cf0 .ar(1, bufnum, \cf3 BufRateScale\cf0 .kr(bufnum), trig, 0, 0)\
	)\
\}).writeDefFile;\
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerTellsBufferSize"\cf0 ,\
\{\cf3 arg\cf0  bufnum=0, triggerID=1000, impulsesPerSec=1;\
\cf3 var\cf0  trig, bufferFrames;\
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
trig = \cf3 Impulse\cf0 .kr(impulsesPerSec);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, bufferFrames); \cf2 //send a trigger to the client\cf0 \
\}).writeDefFile;\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerTellsAmp1Chan"\cf0 ,\
\{\cf3 arg\cf0  bufnum=0, in=0, triggerID=3000, impulsesPerSec=10;\
\cf3 var\cf0  trig, amp, numChannels;\
numChannels=1;\
amp = \cf3 Amplitude\cf0 .kr(\cf3 In\cf0 .ar(in, numChannels)); \cf2 //if I put this after the audio generating synthdef,\cf0 \
									\cf2 //hopefully it will get the amplitude of the sound playing\cf0 \
trig = \cf3 Impulse\cf0 .kr(impulsesPerSec);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, amp); \cf2 //send a trigger to the client\cf0 \
\}).writeDefFile;\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerTellsAmp2Chan"\cf0 ,\
\{\cf3 arg\cf0  bufnum=0, in=0, triggerID=3000, impulsesPerSec=10;\
\cf3 var\cf0  trig, amp, numChannels;\
numChannels=2;\
amp = \cf3 Amplitude\cf0 .kr(\cf3 In\cf0 .ar(in, numChannels)); \cf2 //if I put this after the audio generating synthdef,\cf0 \
									\cf2 //hopefully it will get the amplitude of the sound playing\cf0 \
trig = \cf3 Impulse\cf0 .kr(impulsesPerSec);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, amp); \cf2 //send a trigger to the client\cf0 \
\}).writeDefFile;\
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerTellsAmp4Chan"\cf0 ,\
\{\cf3 arg\cf0  bufnum=0, in=0, triggerID=3000, impulsesPerSec=10;\
\cf3 var\cf0  trig, amp, numChannels;\
numChannels=4;\
amp = \cf3 Amplitude\cf0 .kr(\cf3 In\cf0 .ar(in, numChannels)); \cf2 //if I put this after the audio generating synthdef,\cf0 \
									\cf2 //hopefully it will get the amplitude of the sound playing\cf0 \
trig = \cf3 Impulse\cf0 .kr(impulsesPerSec);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, amp); \cf2 //send a trigger to the client\cf0 \
\}).writeDefFile;\
\
\cf2 //From sc-users archive (Modified)\cf0 \
\cf3 SynthDef\cf0 (\cf4 "JASTrigger"\cf0 ,\
\{\cf3 arg\cf0  in=1, thresh=0.004, triggerID = 1;\
	\cf3 var\cf0  trig, amp;\
	amp = \cf3 Amplitude\cf0 .kr(\cf3 AudioIn\cf0 .ar(in));\
	trig = \cf3 Trig1.kr\cf0 (\cf3 AudioIn\cf0 .ar(in) >= thresh, 0.01);\
	\cf3 SendTrig.kr\cf0 (trig, triggerID, amp);\
\}).writeDefFile;\
\
\
\cf2 //From sc-users archive (Modified)\cf0 \
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBuffer"\cf0 ,\
\{\cf3 arg\cf0  out=0, bufnum=0, in=1, thresh = 0.004, amp = 1, durationScaler = 0.2, triggerID = 1;\
	\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool;\
	\
	inAmp = \cf3 Amplitude\cf0 .kr(\cf3 AudioIn\cf0 .ar(in));\
	triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
	gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
	trig = \cf3 Trig1.kr\cf0 (triggerBool, (gatedAmp * amp));\
	\cf3 SendTrig.kr\cf0 (trig, triggerID, gatedAmp * amp); \cf2 //send a trigger to the client\cf0 \
	\cf3 Out\cf0 .ar(out,\
		(\cf3 PlayBuf\cf0 .ar(1, bufnum, \cf3 BufRateScale\cf0 .kr(bufnum), trig, 0, 0) \
		* (gatedAmp * amp)\
		)\
	)\
\}).writeDefFile;\
\
\
\cf2 //From sc-users archive (Modified heavily)\cf0 \
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBufferGranular"\cf0 ,\
\{\cf3 arg\cf0  out=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration = 0.2, triggerID = 1, pan=0.5, centerPosition=0.1, interp=1;\
	\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferDuration;\
	bufferDuration = \cf3 BufDur\cf0 .kr(bufnum);\
	inAmp = \cf3 Amplitude\cf0 .kr(\cf3 AudioIn\cf0 .ar(in));\
	triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
	gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
	outamp = (gatedAmp * amp);\
	trig = \cf3 Trig1.kr\cf0 (triggerBool, outamp);\
	\cf3 SendTrig.kr\cf0 (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
	\cf3 Out\cf0 .ar(out,\cf3 TGrains\cf0 .ar(2, trig, bufnum, 1, bufferDuration*centerPosition , duration, pan, outamp, interp));\
\}).writeDefFile;\
\
\
\cf2 // From: Samuel Pluta <spluta@gmail.com> (badass!)\cf0 \
\cf2 // With modifications by Jonathan Saggau\cf0 \
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap32"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 32; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds); \cf2 // why div, Sam?\cf0 \
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = \cf3 PulseCount\cf0 .kr(trig);\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf2 //As above, only no moving through the buffer.\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap32Static"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition = 200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 32; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = 1;\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap24"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 24; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds); \cf2 // why div, Sam?\cf0 \
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = \cf3 PulseCount\cf0 .kr(trig);\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf2 //As above, only no moving through the buffer.\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap24Static"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 24; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = 1;\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\cf2 // From: Samuel Pluta <spluta@gmail.com> (badass!)\cf0 \
\cf2 // With modifications by Jonathan Saggau\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap16"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 16; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds); \cf2 // why div, Sam?\cf0 \
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = \cf3 PulseCount\cf0 .kr(trig);\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf2 //As above, only no moving through the buffer.\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap16Static"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 16; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = 1;\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap12"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 12; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds); \cf2 // why div, Sam?\cf0 \
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = \cf3 PulseCount\cf0 .kr(trig);\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf2 //As above, only no moving through the buffer.\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap12Static"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 12; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = 1;\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap6"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 6; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds); \cf2 // why div, Sam?\cf0 \
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = \cf3 PulseCount\cf0 .kr(trig);\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf2 //As above, only no moving through the buffer.\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBOlap6Static"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 6; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = 1;\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBNoOlap"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 1; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds); \cf2 // why div, Sam?\cf0 \
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = \cf3 PulseCount\cf0 .kr(trig);\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\
\cf2 //As above, only no moving through the buffer.\cf0 \
\
\cf3 SynthDef\cf0 (\cf4 "JASTriggerBNoOlapStatic"\cf0 ,\
\{\cf3 arg\cf0  outBus=0, bufnum=0, in=1, thresh = 0.004, amp = 1, duration =0.2, triggerID = 1,  envCurve = -7, attackDuration = 0.05, pan=0,  bufferPosition =200;\
\cf3 var\cf0  trig, inAmp, gatedAmp, triggerBool, outamp, bufferFrames,bufRateScale, bufPointer, env, envGenList, outList, trigList, maxNumOverlapSounds;\
\
maxNumOverlapSounds = 1; \cf2 //set this as you like it.  \cf0 \
\
bufferFrames = \cf3 BufFrames\cf0 .kr(bufnum);\
bufRateScale = \cf3 BufRateScale\cf0 .kr(bufnum);\
inAmp = \cf3 Amplitude\cf0 .kr (\cf3 AudioIn\cf0 .ar(in));\
triggerBool = (\cf3 AudioIn\cf0 .ar(in) >= thresh);\
gatedAmp = \cf3 Latch\cf0 .kr(inAmp, triggerBool);\
outamp = (gatedAmp * amp);\
\
trig = \cf3 Trig1.kr\cf0 (triggerBool, duration / maxNumOverlapSounds);\
\cf3 SendTrig.kr\cf0  (trig, triggerID, outamp); \cf2 //send a trigger to the client\cf0 \
\
bufPointer = 1;\
\
env = \cf3 Env\cf0 .perc(attackDuration, (duration - attackDuration), outamp, envCurve);\
             \cf2 //  *perc(attackTime,      releaseTime,                         peakLevel, curve)\cf0 \
trigList = \cf3 List\cf0 .series(maxNumOverlapSounds); \cf2 //List.new doesn't work here? hmmm I dunno why\cf0 \
envGenList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
outList = \cf3 List\cf0 .series(maxNumOverlapSounds);\
\
\
maxNumOverlapSounds.do(\{ \cf3 arg\cf0  i;\
	trigList.put(i, \cf3 PulseDivider\cf0 .kr(trig, maxNumOverlapSounds, i));\
	envGenList.put(i, \cf3 EnvGen\cf0 .kr(env, trigList.at(i)));\
	outList.put(i, \cf3 PlayBuf\cf0 .ar(1, bufnum, bufRateScale, trigList.at(i),(bufPointer*bufferPosition)%bufferFrames)*envGenList.at(i));\
\});\
\cf3 Out\cf0 .ar(outBus, \cf3 Pan2\cf0 .ar(sum(outList), pan));\
\}).writeDefFile;\
\
\cf2 //From sc-users archive (Josh Parmenter)\cf0 \
\
  \cf3 SynthDef\cf0 (\cf4 "JASPitchFollower"\cf0 , \{\
      \cf3 var\cf0  trig, src, pitch, hasPitch;\
      \cf2 //src = SinOsc.ar(MouseX.kr(220, 440), 0, 0.1);\cf0 \
      src = \cf3 AudioIn\cf0 .ar([1, 2]);\
      #pitch, hasPitch = \cf3 Pitch\cf0 .kr(src);\
      \cf2 // send the pitch value out every 0.1 seconds\cf0 \
      \cf3 SendTrig.kr\cf0 (\cf3 Impulse\cf0 .kr(10), 0, pitch);\
      \cf3 Out\cf0 .ar(0, src);\
      \}).writeDefFile;\
)}